<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.hs.pre.model.PreEntry" %>
<%@ page import="com.hs.pre.page.PageUtil" %>
<%@ page import="com.hs.utils.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
List list = new ArrayList(); 
PageUtil pageUtil = (PageUtil)request.getAttribute("pageUtil");
    list = pageUtil.getResultList();
%>

<html>
  <head>
    <base href="<%=basePath%>"> 
    <META content="MSHTML 6.00.2900.3268" name=GENERATOR> 
    <LINK href="<%=basePath%>app/css/default.css" type=text/css rel=stylesheet>
     <script src='<%=basePath%>app/js/json.js'></script>
     <script src='<%=basePath%>dwr/interface/indexer.js'></script>
     <script src='<%=basePath%>dwr/interface/manager.js'></script>
     <script src='<%=basePath%>dwr/engine.js'></script>
     <script src='<%=basePath%>dwr/util.js'></script> 
     <script src='<%=basePath%>app/js/common.js'></script> 
     <script type="text/javascript">
     //添加索引
     function addIndex(){ 
	     var rows = document.getElementsByName("preId"); 
	     var dataStr = '[';
	     if(null != rows){ 
	        for(var i=0;i<rows.length;i++){
	            if(rows[i].checked){   
	               dataStr += dwr.util.getValue('data_'+rows[i].value)+"," ;  
	            }
	        }
	        dataStr = dataStr.substring(0,dataStr.length-1);
	     }
	     dataStr += ']';
	     if(dataStr.length>2){
		     var test = eval(dataStr);
		     //var stu = '[{"id":"2222","fangm":"ddddd"},{"id":"2222","fangm":"ddddd"}]';
		     indexer.addIndex(test,callBackAdd);
	     }else{ 
	        alert("请选择要更新的方剂");
	     }
	     
     }
     function callBackAdd(message){
       // alert(message);
        if(message != ""){
           var objs = message.split(',');
           if(null != objs && objs.length >0){
           		for(var i = 0;i<objs.length;i++){ 
           		   if(objs[i] != ""){
           		      var temp = objs[i];
           		      var arr = temp.split('@');
           		      if(null != arr && arr.length >0){
           		          dwr.util.setValue('zt_'+arr[0],arr[2]);
           		          dwr.util.setValue('sj_'+arr[0],arr[1]);
           		      }
           		   }
           		}
           
           }
        }
     }
     //更新索引
     function updateIndex(){
     
     }
     
     function callBackDel(data){
     
     }
     //删除索引
     function deleteIndex(){
     	if(confirm("确认删除所选方剂的索引？")){ 
	         var rows = document.getElementsByName("preId"); 
		     var dataStr = '';
		     if(null != rows){ 
		        for(var i=0;i<rows.length;i++){
		            if(rows[i].checked){   
		               dataStr += rows[i].value+"," ;  
		            }
		        }
		        dataStr = dataStr.substring(0,dataStr.length-1);
		     } 
		     if(dataStr != ''){  
			     indexer.deleteIndex(dataStr,callBackDel);
		     }else{ 
		        alert("请选择要删除的方剂");
		     }
	     }
     }
     //
     function updateIndexById(id){
        var dataStr ='['+dwr.util.getValue('data_'+id) + ']' ;
        var test = eval(dataStr); 
        indexer.addIndex(test,callBackUpdateById);
     }
     function callBackUpdateById(message){
         if(message != ""){
           var objs = message.split(',');
           if(null != objs && objs.length >0){
           		for(var i = 0;i<objs.length;i++){ 
           		   if(objs[i] != ""){
           		      var temp = objs[i];
           		      var arr = temp.split('@');
           		      if(null != arr && arr.length >0){
           		          dwr.util.setValue('zt_'+arr[0],arr[2]);
           		          dwr.util.setValue('sj_'+arr[0],arr[1]);
           		      }
           		   }
           		}
           
           }
        }
     
     }
      function deleteIndexById(id){ 
        indexer.deleteIndex(id,callBackDel);
     }
      function indexAll(){ 
      	if(confirm("本操作将会重建全部方剂索引，确认要重建吗？")){
        	indexer.indexAll(callBackAdd);
        }
     }
     
     function editPre(){
        var id = "";
        openwindow('../admin/editPre.jsp?preId='+id,'1200','800','_blank');
        //window.location.href="../admin/editPre.jsp";
     } 
     function editPre(){
         var preId = '';
         var count = 0;
         var flag = true;
         var rows = document.getElementsByName("preId");   
	     if(null != rows){ 
	        for(var i=0;i<rows.length;i++){
	            if(rows[i].checked){   
	               preId = rows[i].value;
	               count+=1;
	            }
	            if(count > 1){
	              alert("请选择一个方剂进行编辑");
	              preId = '';
	              flag = false;
	              break;
	            }
	        } 
	        if(!flag)
	          return;
	     }  
	     if('' == preId){
	        alert("请选择方剂进行编辑");
	        return;
	     }
         openwindow('<%=path%>/admin/manage.do?action=edit&preId='+preId,'1100','800','');
     
     }
     function newPre(){ 
       openwindow('<%=path%>/admin/manage.do?action=edit','1100','800','');
     }
     function viewPre(preId){
       openwindow('<%=path%>/app/admin/viewPre.jsp?preId='+preId,'1100','800',''); 
     }
     function delPre(){
         var preIdStr = '';
         var count = 0; 
         var rows = document.getElementsByName("preId");   
	     if(null != rows){ 
	        for(var i=0;i<rows.length;i++){
	            if(rows[i].checked){   
	               preIdStr += rows[i].value+',';
	               count+=1;
	            } 
	        }  
	     }  
	     if(count <= 0)
	        alert("请选择要删除的方剂");
	    manager.delPre(preIdStr,delCallBack);
     }
     function delCallBack(message){ 
        window.location.reload();
     }
     </script>
</HEAD>
<BODY>  

<table cellSpacing=0 align=right cellPadding=0 border=0>
<tr>
<td><form name="form1" action="" method="post">
<table   cellSpacing=0 align=right cellPadding=0 border=0 valign=top>
<tr>
<td><input name="button" type="button" class="buttom"  onclick="newPre();" value="添加方剂"></td>
<td><input name="button" type="button" class="buttom"  onclick="editPre();" value="编辑方剂"></td>
<td><input name="button" type="button" class="buttom"  onclick="delPre();" value="删除方剂"></td>
<td><input name="button" type="button" class="buttom"  onclick="addIndex();" value="批量更新"></td>
<td><input name="button" type="button" class="buttom" onclick="deleteIndex();" value="批量删除"></td>
<td><input name="button" type="button" class="buttom" onclick="indexAll();" value="索引重做"></td>
<td></td>
</tr>
</table>
</td>
</tr>
<tr heigth="5px"><td><br></td></tr>
<tr>
<td>
<DIV class=tab>
<TABLE style="TABLE-LAYOUT: fixed; WORD-BREAK: break-all; TEXT-ALIGN: justify" width=100% cellSpacing=0 cellPadding=0 border=0>
  <TBODY>
  <TR class=top>
    <TD width=3%>序号</TD> 
    <TD width=20%>方名</TD> 
    <TD width=10%>来源</TD> 
    <TD width=15%>药物组成</TD> 
    <TD width=10%>功效</TD> 
    <TD width=10%>主治</TD>
    <TD width=5%>索引状态</TD>
    <TD width=5%>索引时间</TD>
    <TD width=10%>操作</TD> 
    </TR>
   <%
   if(null != list && list.size() >0){
   int size = list.size();
   for(int i=0;i<size;i++){
    PreEntry preEntry =(PreEntry)list.get(i);
   %>
  <TR align=center bgColor=<%if(i%2 == 0){out.println("#fffbff");}else{out.println("#eef1f9");} %>>
    <TD><FONT color=#ff3300><%=i+1 %></FONT></TD>
    <TD class=title><input type="checkbox" value="<%=preEntry.getPreId()%>" name="preId"><a href="javaScript:viewPre('<%=preEntry.getPreId()%>');"><%=Utilities.null2Blank(preEntry.getFangm()) %></a></TD>
    <TD><%=Utilities.null2Blank(preEntry.getChufly()) %></TD>
    <TD><%=Utilities.null2Blank(preEntry.getYaowzc()) %></TD>
    <TD><%=Utilities.null2Blank(preEntry.getGongx()) %></TD>
    <TD><%=Utilities.null2Blank(preEntry.getZhuz())%></TD>
    <TD><span id="zt_<%=preEntry.getId()%>"><%=preEntry.getSuoyinzt() %></span>&nbsp;</TD>
    <TD><span id="sj_<%=preEntry.getId()%>"><%=Utilities.null2Blank(preEntry.getSuoyinsj()) %></span>&nbsp;</TD>
    <TD>&nbsp;<a href="javaScript:updateIndexById('<%=preEntry.getId()%>');">更新</a>&nbsp;<a href="javaScript:deleteIndexById('<%=preEntry.getId()%>');">删除</a>&nbsp;</TD> 
    <div style="display:none" id="data_<%=preEntry.getId()%>"> 
    <%out.println("{");
    out.println("\"id\":\""+preEntry.getId()+"\",");
    out.println("\"fangm\":\""+preEntry.getFangm()+"\",");
    out.println("\"biem\":\""+preEntry.getBiem()+"\",");
    out.println("\"chufly\":\""+preEntry.getChufly()+"\",");
    out.println("\"yaowzc\":\""+preEntry.getYaowzc()+"\",");
    out.println("\"jiaj\":\""+preEntry.getJiaj()+"\","); 
    out.println("\"gongx\":\""+preEntry.getGongx()+"\",");
    out.println("\"zhuz\":\""+preEntry.getZhuz()+"\",");
    out.println("\"zhibff\":\""+preEntry.getZhibff()+"\",");
    out.println("\"yongfyl\":\""+preEntry.getYongfyl()+"\",");
    out.println("\"yongyjj\":\""+preEntry.getYongyjj()+"\","); 
     out.println("\"lincyy\":\""+preEntry.getLincyy()+"\",");
    out.println("\"yaolzy\":\""+preEntry.getYaolzy()+"\",");
    out.println("\"gejls\":\""+preEntry.getGejls()+"\",");
    out.println("\"beiz\":\""+preEntry.getBeiz()+"\"");
    out.println("}"); 
    %></div> 
  </TR> 
    <%} }else{%>
    <TR align=middle bgColor="#eef1f9">
    <TD colspan=9 align="center"><FONT color=red>没有数据</FONT></TD> 
  </TR>  
    <%} %>
  </TBODY></TABLE>
  </DIV></form>
  </td>
  </tr> 
  <tr>
<td>
 <%=pageUtil.viewHTML() %>
 </td>
  </tr> 
 
</table>

<DIV class=clear></DIV>
</BODY></HTML>